
input_sql = "./17.gene_info/gene_info.sql"
with open(input_sql, encoding="utf-8") as file:
    sql_data = file.read()

# 去掉首尾的 INSERT 语句部分，只保留值的部分
values_data = sql_data.split("VALUES")[1].strip(";)").strip()
 
# 将值按行分割成列表
values_list = values_data.split("),\n(")
 
# 计算每个文件应该包含的行数
total_rows = len(values_list)
rows_per_file = total_rows // 75
if total_rows % 10 != 0:
    rows_per_file += 1  # 如果有余数，则最后一个文件将包含剩余的行
 
# 生成 SQL 文件
for i in range(75):
    start_index = i * rows_per_file
    end_index = (i + 1) * rows_per_file  # 更直观的计算方式
    if end_index > total_rows:
        end_index = total_rows
    
    # 取出当前文件应该包含的行
    file_values = values_list[start_index:end_index]
    
    # 构建完整的 SQL 语句
    file_sql = "INSERT INTO gene_info (`genome`, `genome_id`, `chromosome`, `cluster_name`, `transcript_id`, `gene_id`, `start`, `end`, `strand`, `local_gene_density`, `cluster_gene_density`, `pfam`, `gene_description`, `cog_category`, `main_category`, `summary_feature`, `level_1`, `level_2`, `level_3`, `level_4`, `level_5`, `level_6`) VALUES\n"
    file_sql += "),\n(".join(file_values)
    file_sql += ");\n"
    
    # 写入文件
    with open(f"./17.gene_info/gene_info-{i+1}.sql", "w", encoding="utf-8") as file:
        file.write(file_sql)